#[derive(Debug, PartialEq)]
pub enum TokenKind {
    // 基础数据值
    Int(i32),
    Float(f64),
    Bool(bool),
    Str,

    // 符号
    Add,
    Sub,
    Mul,
    Div,
    LF,

    EOF,
}

#[derive(Debug, PartialEq)]
pub struct Token {
    pub kind: TokenKind,
    pub text: String,
    pub span: Span,
}

#[derive(Debug, PartialEq, Clone, Eq, Copy)]
pub struct Span {
    pub start: usize,
    pub end: usize,
}

impl Token {
    pub fn int(text: String, span: Span) -> Self {
        Token {
            kind: TokenKind::Int(text.parse().unwrap()),
            text: text,
            span,
        }
    }

    pub fn float(text: String, span: Span) -> Self {
        Token {
            kind: TokenKind::Float(text.parse().unwrap()),
            text: text,
            span,
        }
    }

    pub fn bool(text: String, span: Span) -> Self {
        Token {
            kind: TokenKind::Bool(text.parse().unwrap()),
            text,
            span,
        }
    }

    pub fn str(text: String, span: Span) -> Self {
        Token { kind: TokenKind::Str, text, span }
    }

    pub fn add(start: usize, end: usize) -> Self {
        Token { kind: TokenKind::Add, text: "+".to_string(), span: Span{start, end} }
    }

    pub fn sub(start: usize, end: usize) -> Self {
        Token { kind: TokenKind::Sub, text: "-".to_string(), span: Span{start, end} }
    }

    pub fn mul(start: usize, end: usize) -> Self {
        Token { kind: TokenKind::Mul, text: "*".to_string(), span: Span{start, end} }
    }

    pub fn div(start: usize, end: usize) -> Self {
        Token { kind: TokenKind::Div, text: "/".to_string(), span: Span{start, end} }
    }

    pub fn lf(pos: usize) -> Self {
        Token { kind: TokenKind::LF, text: "\n".to_string(), span: Span{start: pos, end: pos} }
    }

    pub fn eof(pos: usize) -> Self {
        Token { kind: TokenKind::EOF, text: "".to_string(), span: Span{start: pos, end: pos} }
    }
}
